package com.storm.controller
{
	import flash.display.DisplayObject;
	
	import mx.effects.Tween;

	public class MoveController {
		public function MoveController() {
		}
		
		private var _moveTween:Tween;
		public function moveTo(item:DisplayObject, x:Number, y:Number, duration:Number = 500, moveHandler:Function = null):void {
			function moveUpdate(datas:Array):void {
				item.x = datas[0];
				item.y = datas[1];
			}
			function moveEnd(datas:Array):void {
				moveUpdate(datas);
				if (moveHandler !== null) {
					moveHandler();
				}
			}
			
			if (this._moveTween) {
				this._moveTween.pause();
			}
			
			this._moveTween = new Tween(this, [item.x, item.y], [x, y], duration, -1, moveUpdate, moveEnd);
		}
	}
}